package com.hrm.company.service;

import com.hrm.common.util.IdWorker;
import com.hrm.company.dao.CompanyDao;
import com.hrm.domain.company.Company;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class CompanyService {
    @Autowired
    private CompanyDao companyDao;

    @Autowired
    private IdWorker idWorker;

    /**
     * 保存企业
     * 前端传值+id生成器+激活审核状态
     */
    public void addCompany(Company company) {
        String id = idWorker.nextId() + "";
        company.setId(id);
        company.setAuditState("1");
        company.setState(1);
        companyDao.save(company);
    }

    /**
     * 更新企业
     * id查询+修改属性值+更新
     */
    public void updateCompany(Company company) {
        Company temp = companyDao.findById(company.getId()).get();
        temp.setName(company.getName());
        temp.setCompanyPhone(company.getCompanyPhone());

        companyDao.save(temp);
    }
    /**
     * 删除企业
     */
    public void deleteCompany(String id) {
        companyDao.deleteById(id);
    }
    /**
     * 根据id查询企业
     */
    public Company findCompanyById(String id) {
        return companyDao.findById(id).get();
    }
    /**
     * 查询全部企业列表
     */
    public List<Company> findCompanies() {
        return companyDao.findAll();
    }
}
